package org.intellij.doctree.actions;

import com.intellij.openapi.actionSystem.AnActionEvent;
import org.intellij.doctree.DocTree;
import org.intellij.doctree.DocTreeComponent;
import org.intellij.doctree.node.DocTreeNode;

import javax.swing.tree.TreePath;

public class MoveDown extends TreeEditAction {

    public void actionPerformed(AnActionEvent e) {
        DocTree tree = getTree(e);
        if (tree == null) return;

        DocTreeNode node = tree.getCurrentNode();
        DocTreeComponent component = getComponent(e);

        component.moveNodeDown(node);

        tree.setSelectionPath(new TreePath(node.getPath()));
    }

    public void update(AnActionEvent e) {
        boolean actionEnabled = false;
        DocTree tree = getTree(e);
        if (tree != null) {
            DocTreeNode node = tree.getCurrentNode();
            if (node != null && node.isEditable()) actionEnabled = true;
        }
        e.getPresentation().setEnabled(actionEnabled);
    }

}
